package com.acegear.horizon.domain.events;


import com.acegear.horizon.domain.models.constraint.RecommendType;
import com.acegear.horizon.domain.models.jpa.Recommend;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by guoweike on 17/2/7.
 */
public class RecommendCreateEvent extends BaseEvent {

  private RecommendType type;

  private List<RecommendItem> body;

  public RecommendCreateEvent() {
  }


  public RecommendCreateEvent(RecommendType type, List<RecommendItem> body) {
    this.type = type;
    this.body = body;
    genEventId();
  }

  public RecommendType getType() {
    return type;
  }

  public void setType(RecommendType type) {
    this.type = type;
  }

  public List<Recommend> getBody() {
    List<Recommend> items = new ArrayList<>();
    body.forEach((item ->
        items.add(new Recommend(type, item.getExternalId(), item.getPos()))
    ));
    return items;
  }

  public void setBody(List<RecommendItem> body) {
    this.body = body;
  }

  @Override
  public String routingKey() {
    return "horizon.domain.recommend.new";
  }
}

@JsonIgnoreProperties(ignoreUnknown = true)
class RecommendItem {

  private Long id;
  private Long recommendId;
  private Long externalId;
  private Integer pos;

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public Long getRecommendId() {
    return recommendId;
  }

  public void setRecommendId(Long recommendId) {
    this.recommendId = recommendId;
  }

  public Long getExternalId() {
    return externalId;
  }

  public void setExternalId(Long externalId) {
    this.externalId = externalId;
  }

  public Integer getPos() {
    return pos;
  }

  public void setPos(Integer pos) {
    this.pos = pos;
  }
}